#!/bin/bash
#Rotate the Nginx logs to prevent a single logfile from consuming too much disk space. 
LOGS_PATH=/mnt/nginx/logs
YESTERDAY=$(date -d "yesterday" +%Y-%m-%d)
cp ${LOGS_PATH}/access.log ${LOGS_PATH}/access_${YESTERDAY}.log
cp ${LOGS_PATH}/error.log ${LOGS_PATH}/error_${YESTERDAY}.log
echo "copy ${LOGS_PATH}/access.log to ${LOGS_PATH}/access_${YESTERDAY}.log"
echo "" > ${LOGS_PATH}/access.log
echo "" > ${LOGS_PATH}/error.log
echo "clear ${LOGS_PATH}/access.log"
## 向 Nginx 主进程发送 USR1 信号。USR1 信号是重新打开日志文件
#kill -USR1 $(cat /mnt/nginx/logs/nginx.pid)
echo "nginx log cut success!"
